source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-332.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.181.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
725 819 1303 1760 1537 1739 1587 1498 1544 1843 1431 1268 1298 1111 793 1325
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1306 1247 1528 1529 1231 568 1406 1342 1341 1123 1062 947 821 1215 1575 1451
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
1484 995 1216 600 974 1151 1207 964 1090 1498 820 1046 842 669 813 513
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
1299 1228 1430 765 1436 1035 1223 501 522 1018 971 985 963 243 775 499
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
648 153 284 798 1107 1316 1197 1013 1141 926 381 356 360 942 1450 1468
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
483 945 523 263 93 174 388 484 1094 1627 915 246 285 142 39 8
97 98 99 100
94 159 224 1107
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip
[1,] 0.90271970 0.3140273 0.3533610 0.01541472
[2,] 0.04017704 -0.8478021 -0.8286974 0.49004244
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
fecha_cnt precip tmax tmin
0.9802178 0.9774398 0.9767485 0.9747406
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 50.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :263 Median :154.0 Median : 5.000 Median :0
Mean : 7.117 Mean :265 Mean :155.6 Mean : 9.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:294 3rd Qu.:180.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.6781 Median : 87.0
Mean : 0.00331 Mean :38.55 Mean : -4.1504 Mean : 283.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4483 3rd Qu.: 534.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.0
1st Qu.: 2.000 1st Qu.:122.0 1st Qu.: 28.00 1st Qu.: 6.0
Median : 4.000 Median :156.0 Median : 58.00 Median : 15.0
Mean : 5.995 Mean :150.9 Mean : 54.71 Mean : 18.8
3rd Qu.:11.000 3rd Qu.:183.0 3rd Qu.: 84.00 3rd Qu.: 27.0
Max. :12.000 Max. :263.0 Max. : 177.00 Max. :116.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.2892
Median :0.000000 Median : 0.0000 Median :41.15 Median : -2.8194
Mean :0.000541 Mean : 0.6697 Mean :40.48 Mean : -2.8146
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 69.0
Median : 421.0
Mean : 526.6
3rd Qu.: 775.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-115.0 Min. : 62.00 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 48.5 1st Qu.: 78.00 1st Qu.:0
Median : 9.000 Median :141.0 Median : 74.0 Median : 90.00 Median :0
Mean : 6.729 Mean :144.4 Mean : 75.1 Mean : 98.56 Mean :0
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.: 109.0 3rd Qu.:109.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -8.411 1st Qu.: 35.0
Median : 0.000 Median :42.44 Median : -4.846 Median : 143.0
Mean : 4.777 Mean :41.42 Mean : -4.782 Mean : 403.2
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 50.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :263 Median :154.0 Median : 5.000 Median :0
Mean : 7.117 Mean :265 Mean :155.6 Mean : 9.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:294 3rd Qu.:180.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.6781 Median : 87.0
Mean : 0.00331 Mean :38.55 Mean : -4.1504 Mean : 283.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4483 3rd Qu.: 534.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:123.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :155.0 Median : 54.00 Median :15.00
Mean :2.819 Mean :149.5 Mean : 50.12 Mean :18.03
3rd Qu.:4.000 3rd Qu.:180.0 3rd Qu.: 79.00 3rd Qu.:26.00
Max. :8.000 Max. :256.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0e+00 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0e+00 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0e+00 Median : 0.0000 Median :41.11 Median : -2.9056
Mean :6e-04 Mean : 0.9154 Mean :40.47 Mean : -2.8295
3rd Qu.:0e+00 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :6e+00 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 412.0
Mean : 512.9
3rd Qu.: 750.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0
1st Qu.:10.00 1st Qu.:120.0 1st Qu.: 33.00 1st Qu.: 6
Median :11.00 Median :157.0 Median : 66.00 Median : 15
Mean :10.99 Mean :153.1 Mean : 61.92 Mean : 20
3rd Qu.:12.00 3rd Qu.:188.0 3rd Qu.: 94.00 3rd Qu.: 29
Max. :12.00 Max. :263.0 Max. : 156.00 Max. :116
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.2892
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.7331
Mean :0.0004474 Mean : 0.2831 Mean :40.50 Mean : -2.7913
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 71.0
Median : 445.0
Mean : 548.2
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-115.0 Min. : 62.00 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 48.5 1st Qu.: 78.00 1st Qu.:0
Median : 9.000 Median :141.0 Median : 74.0 Median : 90.00 Median :0
Mean : 6.729 Mean :144.4 Mean : 75.1 Mean : 98.56 Mean :0
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.: 109.0 3rd Qu.:109.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -8.411 1st Qu.: 35.0
Median : 0.000 Median :42.44 Median : -4.846 Median : 143.0
Mean : 4.777 Mean :41.42 Mean : -4.782 Mean : 403.2
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 50.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :263 Median :154.0 Median : 5.000 Median :0
Mean : 7.117 Mean :265 Mean :155.6 Mean : 9.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:294 3rd Qu.:180.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.6781 Median : 87.0
Mean : 0.00331 Mean :38.55 Mean : -4.1504 Mean : 283.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4483 3rd Qu.: 534.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:123.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :155.0 Median : 54.00 Median :15.00
Mean :2.819 Mean :149.5 Mean : 50.12 Mean :18.03
3rd Qu.:4.000 3rd Qu.:180.0 3rd Qu.: 79.00 3rd Qu.:26.00
Max. :8.000 Max. :256.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0e+00 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0e+00 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0e+00 Median : 0.0000 Median :41.11 Median : -2.9056
Mean :6e-04 Mean : 0.9154 Mean :40.47 Mean : -2.8295
3rd Qu.:0e+00 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :6e+00 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 412.0
Mean : 512.9
3rd Qu.: 750.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0
1st Qu.:10.00 1st Qu.:120.0 1st Qu.: 33.00 1st Qu.: 6
Median :11.00 Median :157.0 Median : 66.00 Median : 15
Mean :10.99 Mean :153.1 Mean : 61.92 Mean : 20
3rd Qu.:12.00 3rd Qu.:188.0 3rd Qu.: 94.00 3rd Qu.: 29
Max. :12.00 Max. :263.0 Max. : 156.00 Max. :116
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.2892
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.7331
Mean :0.0004474 Mean : 0.2831 Mean :40.50 Mean : -2.7913
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 71.0
Median : 445.0
Mean : 548.2
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-115.00 Min. : 62.00
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 48.50 1st Qu.: 78.00
Median : 9.000 Median :141.0 Median : 74.00 Median : 90.00
Mean : 6.731 Mean :144.4 Mean : 75.03 Mean : 97.66
3rd Qu.:11.000 3rd Qu.:178.0 3rd Qu.: 109.00 3rd Qu.:109.00
Max. :12.000 Max. :331.0 Max. : 223.00 Max. :259.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -8.411
Median :0 Median : 0.000 Median :42.44 Median : -4.488
Mean :0 Mean : 4.796 Mean :41.42 Mean : -4.773
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787
Max. :0 Max. :892.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 35.0
Median : 143.0
Mean : 402.8
3rd Qu.: 370.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 37.0 Min. :-11.00 Min. :279.0 Min. :0
1st Qu.: 2.750 1st Qu.:108.2 1st Qu.: 49.75 1st Qu.:294.2 1st Qu.:0
Median : 5.500 Median :127.0 Median : 78.50 Median :307.0 Median :0
Mean : 6.125 Mean :157.5 Mean : 90.75 Mean :323.1 Mean :0
3rd Qu.: 9.000 3rd Qu.:194.0 3rd Qu.:137.25 3rd Qu.:332.8 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :204.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.42 1st Qu.: -8.649 1st Qu.: 19.0
Median :0 Median :42.33 Median : -8.517 Median : 262.0
Mean :0 Mean :40.50 Mean : -7.103 Mean : 493.2
3rd Qu.:0 3rd Qu.:42.54 3rd Qu.: -2.827 3rd Qu.: 437.2
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 50.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :263 Median :154.0 Median : 5.000 Median :0
Mean : 7.117 Mean :265 Mean :155.6 Mean : 9.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:294 3rd Qu.:180.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.6781 Median : 87.0
Mean : 0.00331 Mean :38.55 Mean : -4.1504 Mean : 283.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4483 3rd Qu.: 534.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:123.0 1st Qu.: 25.00 1st Qu.: 6.00
Median :3.000 Median :155.0 Median : 54.00 Median :15.00
Mean :2.819 Mean :149.5 Mean : 50.12 Mean :18.03
3rd Qu.:4.000 3rd Qu.:180.0 3rd Qu.: 79.00 3rd Qu.:26.00
Max. :8.000 Max. :256.0 Max. : 177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0e+00 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0e+00 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -5.3456
Median :0e+00 Median : 0.0000 Median :41.11 Median : -2.9056
Mean :6e-04 Mean : 0.9154 Mean :40.47 Mean : -2.8295
3rd Qu.:0e+00 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :6e+00 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 64.0
Median : 412.0
Mean : 512.9
3rd Qu.: 750.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0
1st Qu.:10.00 1st Qu.:120.0 1st Qu.: 33.00 1st Qu.: 6
Median :11.00 Median :157.0 Median : 66.00 Median : 15
Mean :10.99 Mean :153.1 Mean : 61.92 Mean : 20
3rd Qu.:12.00 3rd Qu.:188.0 3rd Qu.: 94.00 3rd Qu.: 29
Max. :12.00 Max. :263.0 Max. : 156.00 Max. :116
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.2892
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.7331
Mean :0.0004474 Mean : 0.2831 Mean :40.50 Mean : -2.7913
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 71.0
Median : 445.0
Mean : 548.2
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-115.0 Min. : 62.00 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 49.0 1st Qu.: 77.00 1st Qu.:0
Median : 9.000 Median :143.0 Median : 75.0 Median : 87.00 Median :0
Mean : 6.747 Mean :146.2 Mean : 76.1 Mean : 89.87 Mean :0
3rd Qu.:11.000 3rd Qu.:183.0 3rd Qu.: 111.0 3rd Qu.:101.00 3rd Qu.:0
Max. :12.000 Max. :326.0 Max. : 219.0 Max. :155.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -8.411 1st Qu.: 34.0
Median : 0.000 Median :42.44 Median : -4.010 Median : 127.0
Mean : 4.849 Mean :41.44 Mean : -4.533 Mean : 394.2
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :121.0 Min. :0
1st Qu.: 2.000 1st Qu.:110.2 1st Qu.: 48.00 1st Qu.:137.0 1st Qu.:0
Median : 7.500 Median :128.0 Median : 67.00 Median :148.0 Median :0
Mean : 6.611 Mean :130.0 Mean : 66.76 Mean :158.1 Mean :0
3rd Qu.:11.000 3rd Qu.:150.0 3rd Qu.: 87.00 3rd Qu.:171.0 3rd Qu.:0
Max. :12.000 Max. :331.0 Max. :223.00 Max. :259.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.69 1st Qu.: -8.624 1st Qu.: 100.5
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 4.385 Mean :41.25 Mean : -6.641 Mean : 470.0
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 37.0 Min. :-11.00 Min. :279.0 Min. :0
1st Qu.: 2.750 1st Qu.:108.2 1st Qu.: 49.75 1st Qu.:294.2 1st Qu.:0
Median : 5.500 Median :127.0 Median : 78.50 Median :307.0 Median :0
Mean : 6.125 Mean :157.5 Mean : 90.75 Mean :323.1 Mean :0
3rd Qu.: 9.000 3rd Qu.:194.0 3rd Qu.:137.25 3rd Qu.:332.8 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :204.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.42 1st Qu.: -8.649 1st Qu.: 19.0
Median :0 Median :42.33 Median : -8.517 Median : 262.0
Mean :0 Mean :40.50 Mean : -7.103 Mean : 493.2
3rd Qu.:0 3rd Qu.:42.54 3rd Qu.: -2.827 3rd Qu.: 437.2
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 50.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :263 Median :154.0 Median : 5.000 Median :0
Mean : 7.117 Mean :265 Mean :155.6 Mean : 9.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:294 3rd Qu.:180.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :39.88 Median : -3.6781 Median : 87.0
Mean : 0.00331 Mean :38.55 Mean : -4.1504 Mean : 283.3
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4483 3rd Qu.: 534.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 71.0 Min. :-36.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:150.0 1st Qu.: 50.00 1st Qu.: 6.00
Median :3.000 Median :169.0 Median : 69.00 Median :14.00
Mean :3.134 Mean :170.1 Mean : 67.53 Mean :17.78
3rd Qu.:4.000 3rd Qu.:189.0 3rd Qu.: 86.00 3rd Qu.:25.00
Max. :8.000 Max. :256.0 Max. :177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.6156
Median :0.0000000 Median : 0.0000 Median :40.95 Median : -2.9553
Mean :0.0001772 Mean : 0.0558 Mean :40.21 Mean : -2.9190
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4914
Max. :2.0000000 Max. :65.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 43.0
Median : 176.0
Mean : 362.7
3rd Qu.: 611.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:121.0 1st Qu.: 29.00 1st Qu.: 4.00
Median :11.00 Median :164.0 Median : 64.00 Median :10.00
Mean :10.97 Mean :156.7 Mean : 60.15 Mean :11.61
3rd Qu.:12.00 3rd Qu.:194.0 3rd Qu.: 94.00 3rd Qu.:18.00
Max. :12.00 Max. :263.0 Max. : 150.00 Max. :46.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.0000000 Median : 0.000 Median :40.95 Median : -2.3308
Mean :0.0006036 Mean : 0.185 Mean :40.27 Mean : -2.5458
3rd Qu.:0.0000000 3rd Qu.: 0.000 3rd Qu.:41.98 3rd Qu.: 0.5706
Max. :3.0000000 Max. :338.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 515
Mean : 555
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.00 Min. :-121.000 Min. : 0.00
1st Qu.:1.000 1st Qu.: 82.00 1st Qu.: -9.000 1st Qu.: 7.00
Median :2.000 Median :103.00 Median : 10.000 Median :16.00
Mean :2.033 Mean : 97.97 Mean : 6.764 Mean :18.66
3rd Qu.:3.000 3rd Qu.:120.00 3rd Qu.: 26.000 3rd Qu.:28.00
Max. :7.000 Max. :192.00 Max. : 71.000 Max. :72.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.70 1st Qu.: -4.127
Median :0.000000 Median : 0.000 Median :41.65 Median : -2.654
Mean :0.001655 Mean : 3.057 Mean :41.10 Mean : -2.607
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 0.595
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 515
Median : 735
Mean : 887
3rd Qu.:1005
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 8.00 Min. :-15.0 Min. :-75.00 Min. : 21.00 Min. :0
1st Qu.:11.00 1st Qu.:119.0 1st Qu.: 44.00 1st Qu.: 33.00 1st Qu.:0
Median :11.00 Median :146.0 Median : 69.00 Median : 41.00 Median :0
Mean :11.05 Mean :142.7 Mean : 66.97 Mean : 44.03 Mean :0
3rd Qu.:12.00 3rd Qu.:172.0 3rd Qu.: 92.00 3rd Qu.: 53.00 3rd Qu.:0
Max. :12.00 Max. :263.0 Max. :156.00 Max. :116.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.47 1st Qu.: -5.8728 1st Qu.: 58.0
Median : 0.0000 Median :42.14 Median : -3.7892 Median : 336.0
Mean : 0.5642 Mean :41.15 Mean : -3.4944 Mean : 528.7
3rd Qu.: 0.0000 3rd Qu.:43.12 3rd Qu.: 0.3264 3rd Qu.: 667.0
Max. :382.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-115.0 Min. : 62.00 Min. :0
1st Qu.: 2.000 1st Qu.:117.0 1st Qu.: 49.0 1st Qu.: 77.00 1st Qu.:0
Median : 9.000 Median :143.0 Median : 75.0 Median : 87.00 Median :0
Mean : 6.747 Mean :146.2 Mean : 76.1 Mean : 89.87 Mean :0
3rd Qu.:11.000 3rd Qu.:183.0 3rd Qu.: 111.0 3rd Qu.:101.00 3rd Qu.:0
Max. :12.000 Max. :326.0 Max. : 219.0 Max. :155.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -8.411 1st Qu.: 34.0
Median : 0.000 Median :42.44 Median : -4.010 Median : 127.0
Mean : 4.849 Mean :41.44 Mean : -4.533 Mean : 394.2
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :121.0 Min. :0
1st Qu.: 2.000 1st Qu.:110.2 1st Qu.: 48.00 1st Qu.:137.0 1st Qu.:0
Median : 7.500 Median :128.0 Median : 67.00 Median :148.0 Median :0
Mean : 6.611 Mean :130.0 Mean : 66.76 Mean :158.1 Mean :0
3rd Qu.:11.000 3rd Qu.:150.0 3rd Qu.: 87.00 3rd Qu.:171.0 3rd Qu.:0
Max. :12.000 Max. :331.0 Max. :223.00 Max. :259.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.69 1st Qu.: -8.624 1st Qu.: 100.5
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 4.385 Mean :41.25 Mean : -6.641 Mean : 470.0
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 37.0 Min. :-11.00 Min. :279.0 Min. :0
1st Qu.: 2.750 1st Qu.:108.2 1st Qu.: 49.75 1st Qu.:294.2 1st Qu.:0
Median : 5.500 Median :127.0 Median : 78.50 Median :307.0 Median :0
Mean : 6.125 Mean :157.5 Mean : 90.75 Mean :323.1 Mean :0
3rd Qu.: 9.000 3rd Qu.:194.0 3rd Qu.:137.25 3rd Qu.:332.8 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :204.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.42 1st Qu.: -8.649 1st Qu.: 19.0
Median :0 Median :42.33 Median : -8.517 Median : 262.0
Mean :0 Mean :40.50 Mean : -7.103 Mean : 493.2
3rd Qu.:0 3rd Qu.:42.54 3rd Qu.: -2.827 3rd Qu.: 437.2
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 50.0 Min. : 0.00 Min. :0
1st Qu.: 5.000 1st Qu.:213.0 1st Qu.:116.0 1st Qu.: 4.00 1st Qu.:0
Median : 5.000 Median :231.0 Median :133.0 Median :10.00 Median :0
Mean : 5.586 Mean :231.8 Mean :134.1 Mean :15.74 Mean :0
3rd Qu.: 6.000 3rd Qu.:249.0 3rd Qu.:153.0 3rd Qu.:26.00 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :244.0 Max. :73.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:36.85 1st Qu.: -6.3392 1st Qu.: 25.0
Median : 0.00000 Median :40.38 Median : -3.7881 Median : 64.0
Mean : 0.00677 Mean :38.60 Mean : -4.4900 Mean : 237.1
3rd Qu.: 0.00000 3rd Qu.:42.11 3rd Qu.: 0.3994 3rd Qu.: 412.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :181.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:258.0 1st Qu.:144.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :282.0 Median :167.0 Median : 3.000 Median :0
Mean : 7.924 Mean :282.4 Mean :166.8 Mean : 5.542 Mean :0
3rd Qu.: 9.000 3rd Qu.:306.0 3rd Qu.:191.0 3rd Qu.: 9.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :31.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.85 Median : -3.6325 Median : 91.0
Mean : 0.00148 Mean :38.53 Mean : -3.9716 Mean : 307.7
3rd Qu.: 0.00000 3rd Qu.:41.48 3rd Qu.: 0.4483 3rd Qu.: 582.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 71.0 Min. :-36.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:150.0 1st Qu.: 50.00 1st Qu.: 6.00
Median :3.000 Median :169.0 Median : 69.00 Median :14.00
Mean :3.134 Mean :170.1 Mean : 67.53 Mean :17.78
3rd Qu.:4.000 3rd Qu.:189.0 3rd Qu.: 86.00 3rd Qu.:25.00
Max. :8.000 Max. :256.0 Max. :177.00 Max. :93.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.6156
Median :0.0000000 Median : 0.0000 Median :40.95 Median : -2.9553
Mean :0.0001772 Mean : 0.0558 Mean :40.21 Mean : -2.9190
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4914
Max. :2.0000000 Max. :65.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 43.0
Median : 176.0
Mean : 362.7
3rd Qu.: 611.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:121.0 1st Qu.: 29.00 1st Qu.: 4.00
Median :11.00 Median :164.0 Median : 64.00 Median :10.00
Mean :10.97 Mean :156.7 Mean : 60.15 Mean :11.61
3rd Qu.:12.00 3rd Qu.:194.0 3rd Qu.: 94.00 3rd Qu.:18.00
Max. :12.00 Max. :263.0 Max. : 150.00 Max. :46.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.0000000 Median : 0.000 Median :40.95 Median : -2.3308
Mean :0.0006036 Mean : 0.185 Mean :40.27 Mean : -2.5458
3rd Qu.:0.0000000 3rd Qu.: 0.000 3rd Qu.:41.98 3rd Qu.: 0.5706
Max. :3.0000000 Max. :338.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 515
Mean : 555
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.00 Min. :-121.000 Min. : 0.00
1st Qu.:1.000 1st Qu.: 82.00 1st Qu.: -9.000 1st Qu.: 7.00
Median :2.000 Median :103.00 Median : 10.000 Median :16.00
Mean :2.033 Mean : 97.97 Mean : 6.764 Mean :18.66
3rd Qu.:3.000 3rd Qu.:120.00 3rd Qu.: 26.000 3rd Qu.:28.00
Max. :7.000 Max. :192.00 Max. : 71.000 Max. :72.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.70 1st Qu.: -4.127
Median :0.000000 Median : 0.000 Median :41.65 Median : -2.654
Mean :0.001655 Mean : 3.057 Mean :41.10 Mean : -2.607
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 0.595
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 515
Median : 735
Mean : 887
3rd Qu.:1005
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 8.00 Min. :-15.0 Min. :-75.00 Min. : 21.00 Min. :0
1st Qu.:11.00 1st Qu.:119.0 1st Qu.: 44.00 1st Qu.: 33.00 1st Qu.:0
Median :11.00 Median :146.0 Median : 69.00 Median : 41.00 Median :0
Mean :11.05 Mean :142.7 Mean : 66.97 Mean : 44.03 Mean :0
3rd Qu.:12.00 3rd Qu.:172.0 3rd Qu.: 92.00 3rd Qu.: 53.00 3rd Qu.:0
Max. :12.00 Max. :263.0 Max. :156.00 Max. :116.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.47 1st Qu.: -5.8728 1st Qu.: 58.0
Median : 0.0000 Median :42.14 Median : -3.7892 Median : 336.0
Mean : 0.5642 Mean :41.15 Mean : -3.4944 Mean : 528.7
3rd Qu.: 0.0000 3rd Qu.:43.12 3rd Qu.: 0.3264 3rd Qu.: 667.0
Max. :382.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. : 3.0 Min. :-48.0 Min. : 66.00 Min. :0
1st Qu.:10.00 1st Qu.:144.0 1st Qu.: 78.0 1st Qu.: 80.00 1st Qu.:0
Median :11.00 Median :174.0 Median :106.0 Median : 90.00 Median :0
Mean :10.44 Mean :177.2 Mean :105.7 Mean : 93.89 Mean :0
3rd Qu.:11.00 3rd Qu.:211.0 3rd Qu.:133.0 3rd Qu.:105.50 3rd Qu.:0
Max. :12.00 Max. :326.0 Max. :219.0 Max. :155.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.99 1st Qu.: -8.411 1st Qu.: 22.0
Median : 0.00000 Median :42.43 Median : -4.010 Median : 87.0
Mean : 0.08342 Mean :41.11 Mean : -4.418 Mean : 215.8
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :14.00000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-42.0 Min. :-115.00 Min. : 62.00 Min. :0
1st Qu.:1.000 1st Qu.: 97.0 1st Qu.: 26.00 1st Qu.: 73.00 1st Qu.:0
Median :2.000 Median :118.0 Median : 49.00 Median : 82.00 Median :0
Mean :2.179 Mean :107.8 Mean : 39.54 Mean : 84.91 Mean :0
3rd Qu.:3.000 3rd Qu.:137.0 3rd Qu.: 66.00 3rd Qu.: 95.00 3rd Qu.:0
Max. :6.000 Max. :218.0 Max. : 150.00 Max. :126.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :27.92 Min. :-17.755 Min. : 1.0
1st Qu.: 0.00 1st Qu.:42.06 1st Qu.: -8.411 1st Qu.: 64.0
Median : 0.00 Median :42.56 Median : -4.010 Median : 261.0
Mean : 10.74 Mean :41.85 Mean : -4.675 Mean : 614.6
3rd Qu.: 0.00 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 534.0
Max. :892.00 Max. :43.57 Max. : 2.827 Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :121.0 Min. :0
1st Qu.: 2.000 1st Qu.:110.2 1st Qu.: 48.00 1st Qu.:137.0 1st Qu.:0
Median : 7.500 Median :128.0 Median : 67.00 Median :148.0 Median :0
Mean : 6.611 Mean :130.0 Mean : 66.76 Mean :158.1 Mean :0
3rd Qu.:11.000 3rd Qu.:150.0 3rd Qu.: 87.00 3rd Qu.:171.0 3rd Qu.:0
Max. :12.000 Max. :331.0 Max. :223.00 Max. :259.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.69 1st Qu.: -8.624 1st Qu.: 100.5
Median : 0.000 Median :42.43 Median : -8.411 Median : 261.0
Mean : 4.385 Mean :41.25 Mean : -6.641 Mean : 470.0
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.000 Max. :43.49 Max. : 2.827 Max. :2400.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 37.0 Min. :-11.00 Min. :279.0 Min. :0
1st Qu.: 2.750 1st Qu.:108.2 1st Qu.: 49.75 1st Qu.:294.2 1st Qu.:0
Median : 5.500 Median :127.0 Median : 78.50 Median :307.0 Median :0
Mean : 6.125 Mean :157.5 Mean : 90.75 Mean :323.1 Mean :0
3rd Qu.: 9.000 3rd Qu.:194.0 3rd Qu.:137.25 3rd Qu.:332.8 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :204.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.:0 1st Qu.:41.42 1st Qu.: -8.649 1st Qu.: 19.0
Median :0 Median :42.33 Median : -8.517 Median : 262.0
Mean :0 Mean :40.50 Mean : -7.103 Mean : 493.2
3rd Qu.:0 3rd Qu.:42.54 3rd Qu.: -2.827 3rd Qu.: 437.2
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)